package com.it.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {
    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory){
        //声明redis模板对象
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
        //设置链接工厂
        redisTemplate.setConnectionFactory(factory);
        //
        StringRedisSerializer stringRedisSerializer=new StringRedisSerializer();
        //设置键的序列化
        redisTemplate.setKeySerializer(stringRedisSerializer);
        //设置值得序列化
        redisTemplate.setValueSerializer(stringRedisSerializer);
        return redisTemplate;
    }
}
